import 'package:flutter/material.dart';
import 'package:get/get.dart';

enum AppLanguageType {
  zh,
  en,
}

class LanguageManager extends GetxController {
  static LanguageManager get instance => Get.find();
  
  final _currentLanguage = AppLanguageType.zh.obs;
  
  AppLanguageType get currentLanguage => _currentLanguage.value;
  
  // 语言配置
  static const Map<AppLanguageType, Locale> _locales = {
    AppLanguageType.zh: Locale('zh', 'CN'),
    AppLanguageType.en: Locale('en', 'US'),
  };
  
  static const Map<AppLanguageType, String> _languageNames = {
    AppLanguageType.zh: '中文',
    AppLanguageType.en: 'English',
  };
  
  @override
  void onInit() {
    super.onInit();
    _loadLanguage();
  }
  
  void _loadLanguage() {
    // 这里可以从本地存储加载语言设置
    _currentLanguage.value = AppLanguageType.zh;
  }
  
  // 切换语言
  void switchLanguage(AppLanguageType language) {
    _currentLanguage.value = language;
    final locale = _locales[language];
    if (locale != null) {
      Get.updateLocale(locale);
    }
    // 这里可以保存到本地存储
  }
  
  // 获取当前语言名称
  String get currentLanguageName => _languageNames[_currentLanguage.value] ?? '中文';
  
  // 获取所有支持的语言
  List<AppLanguageType> get supportedLanguages => _languageNames.keys.toList();
  
  // 获取语言名称
  String getLanguageName(AppLanguageType language) {
    return _languageNames[language] ?? '中文';
  }
  
  // 获取当前语言环境
  Locale get currentLocale => _locales[_currentLanguage.value] ?? const Locale('zh', 'CN');
} 